package com.ruoyi.OutboundManagement.controller;

import com.ruoyi.OutboundManagement.domain.PickingOutbound;
import com.ruoyi.OutboundManagement.service.IPickingOutboundService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 领料出库管理Controller
 * 
 * @author admin
 * @date 2024-07-04
 */
@RestController
@RequestMapping("/OutboundManagement/pickingOutbound")
public class PickingOutboundController extends BaseController
{
    @Autowired
    private IPickingOutboundService pickingOutboundService;

    /**
     * 查询领料出库管理列表
     */

    @PreAuthorize("@ss.hasPermi('OutboundManagement:pickingOutbound:list')")
    @GetMapping("/list")
    public TableDataInfo list(PickingOutbound pickingOutbound)
    {
        startPage();
        List<PickingOutbound> list = pickingOutboundService.selectPickingOutboundList(pickingOutbound);
        return getDataTable(list);
    }

    /**
     * 导出领料出库管理列表
     */

    @PreAuthorize("@ss.hasPermi('OutboundManagement:pickingOutbound:export')")
    @Log(title = "领料出库管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PickingOutbound pickingOutbound)
    {
        List<PickingOutbound> list = pickingOutboundService.selectPickingOutboundList(pickingOutbound);
        ExcelUtil<PickingOutbound> util = new ExcelUtil<PickingOutbound>(PickingOutbound.class);
        util.exportExcel(response, list, "领料出库管理数据");
    }

    /**
     * 获取领料出库管理详细信息
     */

    @PreAuthorize("@ss.hasPermi('OutboundManagement:pickingOutbound:query')")
    @GetMapping(value = "/{pickingId}")

    public AjaxResult getInfo(@PathVariable("pickingId") Long pickingId)
    {
        return success(pickingOutboundService.selectPickingOutboundByPickingId(pickingId));
    }

    /**
     * 新增领料出库管理
     */

    @PreAuthorize("@ss.hasPermi('OutboundManagement:pickingOutbound:add')")
    @Log(title = "领料出库管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PickingOutbound pickingOutbound)
    {
        return toAjax(pickingOutboundService.insertPickingOutbound(pickingOutbound));
    }

    /**
     * 修改领料出库管理
     */

    @PreAuthorize("@ss.hasPermi('OutboundManagement:pickingOutbound:edit')")
    @Log(title = "领料出库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PickingOutbound pickingOutbound)
    {
        return toAjax(pickingOutboundService.updatePickingOutbound(pickingOutbound));
    }

    /**
     * 删除领料出库管理
     */

    @PreAuthorize("@ss.hasPermi('OutboundManagement:pickingOutbound:remove')")
    @Log(title = "领料出库管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pickingIds}")

    public AjaxResult remove(@PathVariable Long[] pickingIds)
    {
        return toAjax(pickingOutboundService.deletePickingOutboundByPickingIds(pickingIds));
    }
}
